﻿@model  List<Model.ConsultaToques>

@{
    ViewBag.Title = "Consultar";
}



<br /><br /><br /><br />
<div align="center">
            <img src="~/Content/images/consultas.png" />
    <form method="post">
        <fieldset>
            <legend></legend>
            
            @if (@ViewBag.fecha == true){
            
            <strong> Error! Ingrese fechas nuevamente </strong>
            
            }
            <h2> Ingrese fechas: </h2>
            <label>
            <input class="form-control" type="date" name="fecha1" value="2014-01-01" />
                </label>
            
            <label>
                <input class="form-control" type="date" name="fecha2" value="2014-07-08" />
            </label>
            <br />

            <br />
            <table class="table table-striped" id="tablaPDF">
                <thead>
                    <tr>
                        <th>Nombre Empresa</th>
                        <th>Total</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model)
                    {
                        <tr>
                            <td>@item.nombre</td>
                            <td>@item.total</td>
                        </tr>
                    }
                </tbody>
            </table>


            <input class="btn btn-default" type="submit" value="Buscar" />
            <a class="btn btn-default" href="@Url.Action("Index", "Home")" role="button">Volver</a>
            @*<button onclick="javascript:demoFromHTML();">PDF</button>*@




        </fieldset>
    </form>

</div>



<script type="text/javascript">

    

    function consultarDarsena() {


        var idV = $("#consultar").val();
        var parametros = {
            id: idV
        }

        var promise = $.get("@Url.Action("consultarEmpresa", "Empresa")", parametros);
        promise.done(mostrarNombreEmpresa);
    }

    function mostrarNombreEmpresa(datos) {


        $("#nombreEmpresa").html(datos.nombre)

    }


    function demoFromHTML() {
        var pdf = new jsPDF('p', 'pt', 'letter');
        // source can be HTML-formatted string, or a reference
        // to an actual DOM element from which the text will be scraped.
        source = $('#tablaPDF')[0];

        // we support special element handlers. Register them with jQuery-style 
        // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
        // There is no support for any other type of selectors 
        // (class, of compound) at this time.
        specialElementHandlers = {
            // element with id of "bypass" - jQuery style selector
            '#bypassme': function (element, renderer) {
                // true = "handled elsewhere, bypass text extraction"
                return true
            }
        };
        margins = {
            top: 80,
            bottom: 60,
            left: 40,
            width: 522
        };
        // all coords and widths are in jsPDF instance's declared units
        // 'inches' in this case
        pdf.fromHTML(
        source, // HTML string or DOM elem ref.
        margins.left, // x coord
        margins.top, { // y coord
            'width': margins.width, // max width of content on PDF
            'elementHandlers': specialElementHandlers
        },

        function (dispose) {
            // dispose: object with X, Y of the last line add to the PDF 
            //          this allow the insertion of new lines after html
            pdf.save('Test.pdf');
        }, margins);
    }

</script>
